{{- $params := .Scratch.Get "params" -}}

{{- with .Site.Params.verification.google -}}
    <meta name="google-site-verification" content="{{ . }}" />
{{- end -}}
{{- with .Site.Params.verification.bing -}}
    <meta name="msvalidate.01" content="{{ . }}" />
{{- end -}}
{{- with .Site.Params.verification.yandex -}}
    <meta name="yandex-verification" content="{{ . }}" />
{{- end -}}
{{- with .Site.Params.verification.pinterest -}}
    <meta name="p:domain_verify" content="{{ . }}" />
{{- end -}}
{{- with .Site.Params.verification.baidu -}}
    <meta name="baidu-site-verification" content="{{ . }}" />
{{- end -}}



{{- /* Home SEO */ -}}
{{- if .IsHome -}}
    <script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "WebSite",
        "url": "{{ .Permalink }}",
        {{- with .Site.LanguageCode -}}
            "inLanguage": "{{ . }}",
        {{- end -}}
        {{- with .Site.Author.name -}}
            "author": {
                "@type": "Person",
                "name": {{ . | safeHTML }}
            },
        {{- end -}}
        {{- with .Site.Params.description -}}
            "description": {{ . | safeHTML }},
        {{- end -}}
        {{- $image := $params.featuredimagepreview | default $params.featuredimage -}}
        {{- with .Resources.GetMatch "featured-image" -}}
        {{- $image = .RelPermalink -}}
        {{- end -}}
        {{- with .Resources.GetMatch "featured-image-preview" -}}
        {{- $image = .RelPermalink -}}
        {{- end -}}
        {{- with $image -}}
            "image": {
                "@type": "ImageObject",
                "url": "{{ .Permalink }}",
                "width": {{ .Width }},
                "height": {{ .Height }}
            },
        {{- end -}}
        {{- with .Site.Params.seo.thumbnailUrl -}}
            {{- with dict "Path" . "Resources" $.Resources | partial "function/resource.html" -}}
                "thumbnailUrl": "{{ .Permalink }}",
            {{- else -}}
                "thumbnailUrl": "{{ . | absURL }}",
            {{- end -}}
        {{- end -}}
        {{- with .Site.Copyright -}}
            "license": "{{ . | safeHTML }}",
        {{- end -}}
        "name": {{ .Site.Title | safeHTML }}
    }
    </script>

{{- /* Page SEO */ -}}
{{- else if .IsPage -}}
    <script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": {{ .Title | safeHTML }},
        "inLanguage": "{{ .Site.LanguageCode }}",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "{{ .Permalink }}"
        },
        {{- $images := $params.seo.images | default slice -}}
        {{- if not $images -}}
            {{- with .Resources.GetMatch "featured-image-preview" -}}
                {{- $images = slice "featured-image-preview" -}}
            {{- end -}}
            {{- with .Resources.GetMatch "featured-image" -}}
                {{- $images = slice "featured-image" -}}
            {{- end -}}
        {{- end -}}
        {{- with .Site.Params.seo.image -}}
            {{- $images = $images | default (slice .) -}}
        {{- end -}}
        {{- with $images -}}
            "image": [
                {{- range $index, $value := . -}}
                    {{- if gt $index 0 }},{{ end -}}
                    {{- with dict "Path" $value "Resources" $.Resources | partial "function/resource.html" -}}
                        {
                            "@type": "ImageObject",
                            "url": "{{ .Permalink }}",
                            "width": {{ .Width }},
                            "height": {{ .Height }}
                        }
                    {{- else -}}
                        {{- with $value -}}
                            "{{ . | absURL }}"
                        {{- end -}}
                    {{- end -}}
                {{- end -}}
            ],
        {{- end -}}
        "genre": "{{ .Type }}",
        {{- with .Params.tags -}}
            "keywords": "{{ delimit . ", " }}",
        {{- end -}}
        "wordCount": {{ .WordCount }},
        "url": "{{ .Permalink }}",
        {{- if not .PublishDate.IsZero -}}
            "datePublished": {{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }},
        {{- else if not .Date.IsZero -}}
            "datePublished": {{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }},
        {{- end -}}
        {{- with .Lastmod -}}
            "dateModified": {{ .Format "2006-01-02T15:04:05-07:00" | safeHTML }},
        {{- end -}}
        {{- with .Site.Copyright -}}
            "license": {{ . | safeHTML }},
        {{- end -}}
        {{- $publisherName := default .Site.Author.name | default " " -}}
        {{- $publisherPath := print "data/authors/" $publisherName ".json" -}}
        {{ if (fileExists $publisherPath) -}}
        {{ $publisher := index .Site.Data.authors $publisherName }}
        "publisher": {
            "@type": "Person",
            "name": {{ $publisher.full_name | safeHTML }}
            {{- with $publisher.avatar -}}
            , "image": [
            {
            "@type": "ImageObject",
            "url": "{{ . }}"
            }
            ]
            {{- end -}}
        },
        {{- end -}}
        {{- $authorName := $params.author | default .Site.Author.name | default " " -}}
        {{- $authorPath := print "data/authors/" $authorName ".json" -}}
        {{ if (fileExists $authorPath) -}}
        {{ $author := index .Site.Data.authors $authorName }}
        {{- with $author -}}
            "author": {
                "@type": "Person",
                "name": {{ .full_name | safeHTML }}
            },
        {{- end -}}
        {{- end -}}
        "description": {{ .Description | safeHTML }}
    }
    </script>

{{- with $.Params.categories -}}
{{- $category := index . 0 -}}
{{- with $category -}}
{{- $category = partialCached "function/path.html" . . | printf "/categories/%v" | $.Site.GetPage -}}

<script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "BreadcrumbList",
        "itemListElement": [{
            "@type": "ListItem",
            "position": 1,
            "name": "{{ T "home" }}",
            "item": "{{ $.Site.BaseURL | safeHTML }}"
        },{
            "@type": "ListItem",
            "position": 2,
            "name": {{ $category.Title }},
            "item": {{ $category.Permalink }}
        },{
                "@type": "ListItem",
                "position": 3,
                "name": "{{ $.Title | safeHTML }}"
            }]
    }
</script>
{{- end -}}
{{- end -}}

{{- end -}}
